<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>30.访问器的优先级</title>
</head>

<body>
  <script>
    // set  和name 属性，谁在下面谁的优先级就更高
    // 
    'use strict';
    const user = {
      //name: 'houdunren',
      age: 10,
      set name (value) {
        console.log(value + '后盾人');
        //this.name = value; // 这里这样直接赋值的话会造成循环调用
      },
      name: 'houdunren',

    };
    user.name = 'okkk';
    //console.log(user);

    // 私有化 、封闭属性
    const DATA =  Symbol(); 
    const user2 = {
      [DATA] : {name},
      age: 10,
      set name (value) {
        console.log(value);
        this[DATA].name = value;
      },
     get name() {
      return this[DATA].name;
     }
    };
    user2.name ='hdcms';
    // 由于Symbol是唯一的 不可以用 user[Symbol()].name 修改，起到了封闭属性的效果
    console.log(user2.name);
  </script>
</body>

</html>